import { ActionContext } from 'vuex'
import { getUsername } from '@/https/api'
import IRootModule from '@/store/types'
export interface IstateStudent {
  name: string
}
const state: IstateStudent = {
  name: '小王'
}

export const student = {
  namespaced: true,
  state,
  mutations: {
    UPDDATE_NAME (state: IstateStudent, payload: string): void {
      state.name = payload
    }
  },
  actions: {
    async updateUsername (context: ActionContext<IstateStudent, IRootModule>, payload: string) {
      const res = await getUsername(payload)
      if (res) {
        context.commit('UPDDATE_NAME', res)
      }
    }
  }
}
